package studio.banner.reference.service.impl;

import com.baomidou.mybatisplus.extension.service.additional.query.impl.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.additional.update.impl.LambdaUpdateChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import studio.banner.reference.entity.Aggregate;
import studio.banner.reference.mapper.AggregateMapper;
import studio.banner.reference.service.AggregateService;

import java.util.List;

/**
 * @ClassName AggregateServiceImpl
 * @Deacription TODO
 * @Author Baofeng.Wu
 * @Date 2019/11/2 17:08
 **/
@Service
public class AggregateServiceImpl extends ServiceImpl<AggregateMapper, Aggregate> implements AggregateService {
    @Autowired
    private AggregateMapper aggregateMapper;

    @Override
    public boolean insertAggregate(Aggregate aggregate) {
        return aggregateMapper.insert(aggregate) == 1;
    }

    @Override
    public boolean updateAggregateTitle(String aggregateTitle, Integer aggregateId) {
        return new LambdaUpdateChainWrapper<Aggregate>(aggregateMapper)
                .eq(Aggregate::getId, aggregateId).set(Aggregate::getAggregateTitle, aggregateTitle).update();
    }

    @Override
    public void updateSize(Integer id, Integer updateSize) {
        aggregateMapper.updateSize(id, updateSize);
    }

    @Override
    public List<Aggregate> listAggregatesByUserId(Integer userId) {
        return new LambdaQueryChainWrapper<Aggregate>(aggregateMapper)
                .eq(Aggregate::getUserId, userId).list();
    }

    @Override
    public List<Aggregate> listAggregatesByAggregateTitle(String keyword, Integer userId) {
        return new LambdaQueryChainWrapper<Aggregate>(aggregateMapper)
                .eq(Aggregate::getUserId, userId)
                .like(Aggregate::getAggregateTitle, keyword).list();
    }

    @Override
    public List<Aggregate> listByAggregateType(String aggregateType, Integer userId) {
        return new LambdaQueryChainWrapper<Aggregate>(aggregateMapper)
                .eq(Aggregate::getUserId, userId)
                .eq(Aggregate::getAggregateType, aggregateType).list();
    }
}
